package com.oreilly.ez.fileserver.web;

import io.swagger.annotations.Api;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@Api
@CrossOrigin
@RestController
public abstract class BaseCtrl <T> {

    @GetMapping
    abstract Object find(T item, @PageableDefault Pageable pageable) throws Exception;

    @GetMapping("/{id}")
    abstract Object  findById(@PathVariable String id) throws Exception;

    @PostMapping
    abstract Object add(@RequestBody T item) throws Exception;

    @PutMapping
    @PostMapping("/u")
    abstract Object update(@RequestBody T item) throws Exception;

    @PostMapping("/d")
    @DeleteMapping
    abstract Object delete(String[] ids) throws Exception;
}
